package com.lyshop.guiyingshanding.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.lyshop.guiyingshanding.R;
import com.lyshop.guiyingshanding.bean.DayBean;

import java.util.List;


public class HomeDayAdapter extends CommonAdapter<DayBean> {

    private int mPosition;

    public HomeDayAdapter(Context context, List<DayBean> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_home_index_day, parent, false);
            viewHolder = new ViewHolder(convertView);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.setData(position);
        return convertView;
    }

    class ViewHolder {
        private TextView day_desc;
        private TextView day_time;

        ViewHolder(View itemView) {
            itemView.setTag(ViewHolder.this);
            day_desc = itemView.findViewById(R.id.day_desc);
            day_time = itemView.findViewById(R.id.day_time);
        }

        void setData(int position) {
            DayBean bean = mDatas.get(position);
            day_time.setText(bean.shortDay);
            day_desc.setText(bean.day_desc);

            if (position == mPosition) {
                day_time.setBackgroundResource(R.color.color_blue_07);
                day_time.setTextColor(ContextCompat.getColor(mContext, R.color.white));
            } else {
                day_time.setBackgroundResource(R.color.screen_bg);
                day_time.setTextColor(ContextCompat.getColor(mContext, R.color.color_black_01));
            }

        }
    }

    public void setPosition(int position) {
        this.mPosition = position;
        notifyDataSetChanged();
    }
}
